package com.orange.core.pojo.entity.admin;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.orange.core.pojo.entity.IIntIdModel;
import com.orange.core.pojo.entity.IOperatorModel;
import com.orange.core.pojo.enums.EStatus;
import com.orange.core.validator.group.Update;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.With;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class Admin implements IIntIdModel<Admin>, IOperatorModel<Admin> {

    @NotNull(message = "请求参数不合法", groups = {Update.class})
    @TableId(type = IdType.AUTO)
    private @With Integer id;

    /**
     * 登录账号
     */
    @NotBlank(message = "请输入登录账号")
    private String loginName;

    /**
     * 名字
     */
    @NotBlank(message = "请输入名字")
    private String name;

    /**
     * 手机号
     */
    @NotBlank(message = "请输入手机号")
    private String phone;

    private String email;

    @JsonIgnore
    private String password;

    @TableField(exist = false)
    private String plainPassword;

    /**
     * 状态：0禁用，1启用
     *
     * @see EStatus
     */
    private Integer status;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private LocalDateTime createTime;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @TableField(fill = FieldFill.INSERT)
    private Integer createBy;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private LocalDateTime updateTime;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Integer updateBy;

    /**
     * 角色ids
     */
    @TableField(exist = false)
    private List<Integer> roleIds;

    /**
     * 角色，前端不传
     */
    @TableField(exist = false)
    private List<String> roles;
}
